;;Diff-tree::==(one) | (diff Diff-tree Diff-tree)
;;
;;Diff-tree ::= (one)
;;          ::= (diff Diff-tree Diff-tree)

(define-datatype Diff-tree Diff-tree?
  (one-tree (lst list?))   
  (diff     
   (l Diff-tree?)
   (r Diff-tree?))
  )


;;Example sets for this definition
;;
(define t1 (one-tree '(one)))
(define t2 (diff t1 t1))

;;zero: 1 - (1)
;;zero ::= (diff (one) (one))
;;zero: With (one) being the  least possible  number here ,  
;;       we can define zero by 
;;       subtracting one from one. 
(define zero
  (lambda ()
    (diff
     (one-tree '(one))
     (one-tree '(one))
     )
    )
  )

;;define (one) 
;; 0 - ( -1)

;;defining one
(define one (one-tree '(one)))
;;define minus-1
(define minus-1
  (lambda ()
    (diff
     (zero)
     (one-tree '(one))
     )
    )
  )

;;value-fof: Diff-tree ==> number
;;usage: (value-of dt)
;;purpose 
(define value-of
  (lambda (dt)
    (cases Diff-tree dt
      (one-tree (lst) 1)
      (diff (l r)
            (- (value-of l) (value-of r))
            )
      )
    )
  )

;;is-zero?: Diff-Tree ==> boolean
;;usage: (is-zero? dt)
;;Purpose: This Procedure takes a Diff-tree as input and 
;;         gives a #t if the Diff-Tree represents a 0 
;;         and a #f if the tree represents a non zero number
(define is-zero? 
  (lambda (dt)
  (if (= (value-of dt) 0) 
      #t
      #f
      )
    )
  )

;;predecessor: Diff-tree ==> number 
;;usage:(predecessor dt)
;;purpose: Given a diff-tree ,  this procedure produces the value that
;;         is the  predecessor or  one  lesser than the given value. 
(define predecessor
  (lambda (dt)
    (value-of
       (diff dt one)
       )
    )
  )

;;successor: Diff-tree ==> number 
;;usage:(successor dt)
;;purpose: Given a diff-tree ,  this procedure produces the value that
;;         is the  successor or  one  greater than the given value. 
(define successor
  (lambda (dt)
    (value-of
       (diff dt (minus-1))
       )
    )
  )